#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "bsp_lcd.h"

static void area_blink(void)
{
	while (1)
	{
		bsp_display_segment(AREA_WARNING, 1);
		bsp_display_segment(AREA_CAMERA, 1);
		bsp_display_segment(AREA_BRACKETS_LEFT, 1);
		bsp_display_segment(AREA_BRACKETS_RIGHT, 1);
		bsp_display_segment(AREA_CAR_RIGHT, 1);
		bsp_display_segment(AREA_CAR_LEFT, 1);
		bsp_display_segment(AREA_CAR_BELOW, 1);
		bsp_display_segment(AREA_MPH, 1);
		bsp_display_segment(AREA_KMH, 1);
		bsp_display_segment(AREA_KM, 1);
		bsp_display_segment(AREA_YDS, 1);
		bsp_display_segment(AREA_PHONE, 1);
		bsp_display_segment(AREA_TIRED, 1);
		bsp_display_segment(AREA_GAS_ADD, 1);
		bsp_display_segment(AREA_GAS_PER, 1);
		bsp_display_segment(AREA_WATER_SIGN, 1);
		bsp_display_segment(AREA_WATER_C, 1);
		bsp_display_segment(AREA_WATER_F, 1);
		bsp_display_segment(AREA_TIRED, 1);
		bsp_display_segment(AREA_TIRED, 1);
		bsp_lcd_refresh();
		vTaskDelay(100 / portTICK_PERIOD_MS);
		bsp_display_segment(AREA_WARNING, 0);
		bsp_display_segment(AREA_CAMERA, 0);
		bsp_display_segment(AREA_BRACKETS_LEFT, 0);
		bsp_display_segment(AREA_BRACKETS_RIGHT, 0);
		bsp_display_segment(AREA_CAR_RIGHT, 0);
		bsp_display_segment(AREA_CAR_LEFT, 0);
		bsp_display_segment(AREA_CAR_BELOW, 0);
		bsp_display_segment(AREA_MPH, 0);
		bsp_display_segment(AREA_KMH, 0);
		bsp_display_segment(AREA_KM, 0);
		bsp_display_segment(AREA_YDS, 0);
		bsp_display_segment(AREA_PHONE, 0);
		bsp_display_segment(AREA_TIRED, 0);
		bsp_display_segment(AREA_GAS_ADD, 0);
		bsp_display_segment(AREA_GAS_PER, 0);
		bsp_display_segment(AREA_WATER_SIGN, 0);
		bsp_display_segment(AREA_WATER_C, 0);
		bsp_display_segment(AREA_WATER_F, 0);
		bsp_display_segment(AREA_TIRED, 0);
		bsp_display_segment(AREA_TIRED, 0);
		bsp_lcd_refresh();
		vTaskDelay(100 / portTICK_PERIOD_MS);
	}
	vTaskDelete(NULL);
}

static void road_display(void)
{
	while (1)
	{
		bsp_display_road(5, 3, 1);
		bsp_lcd_refresh();
		vTaskDelay(10 / portTICK_PERIOD_MS);
	}
	vTaskDelete(NULL);
}

static void number_display(void)
{
	int count = 0;
	while (1)
	{
		bsp_display_speed(count % 200, 1);
		bsp_display_speed_limit(count % 200, 1);
		bsp_display_distance(count % 10000, 1);
		bsp_display_gas(count % 200, 1);
		bsp_display_water(count % 1000, 1);
		bsp_display_dir(6, 1);
		bsp_lcd_refresh();
		vTaskDelay(60 / portTICK_PERIOD_MS);
		count++;
	}
	vTaskDelete(NULL);
}

void test_lcd_task(void *arg)
{
	xTaskCreate(area_blink, "area_blink", 2048, NULL, 0, NULL);
	xTaskCreate(road_display, "road_display", 2048, NULL, 0, NULL);
	xTaskCreate(number_display, "number_display", 2048, NULL, 0, NULL);

	while (1)
	{
		vTaskDelay(2000 / portTICK_PERIOD_MS);
	}
}